<?php

/**
 * REDIS HASH LOCK 类
 */
namespace App\Service\AppService;
use App\Service\BaseService;

class RedisHashLock extends BaseService
{
    protected $redis;
    const REDIS_DB = 0;
    public function __construct() 
    {
        $this->redis = $this->getRedisObj();
        $this->redis->select(self::REDIS_DB);
    }
    
    /**
     * 获取Redis Hash Redis Lock
     * @param string $HashMainKey
     * @param string $HashKey
     * @param void $value
     * @return boolean
     */
    public function getLockHash( string $HashMainKey, string $HashKey,string $value = '' )
    {
        if( $this->redis->hExists($HashMainKey,$HashKey) ) {
            return false;
        }
        return $this->redis->hSet($HashMainKey,$HashKey,$value);
    }
    
    /**
     * 解锁
     * @param string $HashMainKey
     * @param string $redisKey
     * @param void $value
     * @return mixed
     */
    public function unLockHash( string $HashMainKey ,string $HashKey, string $value = '' )
    {
       return $this->redis->hDel($HashMainKey,$HashKey);
    }
}